package com.yang.handler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
/**
 * string处理
 * 
 * eg:"a,b" <--> "a_b"
 * 
 * @author yang
 *
 */
public class NameChangeTypeHandler extends BaseTypeHandler<String> {

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType)
			throws SQLException {
		ps.setString(i, parameter.replaceAll(",", "_"));
	}

	@Override
	public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
		String temp = rs.getString(columnName);
		temp = temp.replaceAll("_", ",");
		return temp;
	}

	@Override
	public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		String temp = rs.getString(columnIndex);
		temp = temp.replaceAll("_", ",");
		return temp;
	}

	@Override
	public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		String temp = cs.getString(columnIndex);
		temp = temp.replaceAll("_", ",");
		return temp;
	}


}
